﻿@model IMS_FinanceRecvDue
@{
	ViewBag.Title = (Model.ID > 0 ? "修改" : "新增") + "应收款";
}
@section header {
	@*<link href="~/lib/select2/select2.min.css" rel="stylesheet" asp-append-version="true" />*@
	<style>
		.detail-content-info, .detail-content-label {
			padding: 3px;
		}
	</style>
}
@section quickmenu {
	<td style="padding-right: 0px; padding-left: 10px;">
		<span style="cursor: pointer;" title="返回..." @@click="pageBack">
			<i class="icon-reply icon-2x pull-left icon-border crm-bu-style"></i>
		</span>
	</td>
}

<table style="border:0;margin:0;border-spacing:0;width:100%;padding:0 15px 10px 15px;overflow:auto;table-layout:fixed;">
	<tbody>
		<tr>
			<td class="detail-left-td">
				<div class="detail-panel-div">
					<div class="detail-inner">
						<div class="detail-name-div" title="@(Model.ID > 0 ? Model.SNo : "新增应收款")">
							@(Model.ID > 0 ? Model.SNo : "新增应收款")
						</div>
					</div>
					<div class="detail-heading">
						相关记录
					</div>
					<div class="detail-inner detail-related">
						<div class="detail-list-div-disabled" v-for="(ritem) in related">
							{{ritem.name}}
						</div>
					</div>
					<div class="detail-exit">&nbsp;</div>
				</div>
			</td>
			<td style="vertical-align:top;" class="detail-content-td">
				<div style="width:100%;margin:0;padding:0;" v-show="viewid=='main'">
					<table style="width:100%;">
						<tr>
							<td style="vertical-align:top;">
								<form id="frmEdit">
									<div class="detail-panel-div" style="position:relative;overflow:auto;">
										<table border="0" cellspacing="0" cellpadding="5" style="height:42px;width:100%;table-layout:fixed;">
											<tbody>
												<tr class="detail-content-heading" style="height: 28px;">
													<td>
														<b>&nbsp;基本信息&nbsp;</b>
													</td>
												</tr>
												<tr>
													<td>
														<table border="0" cellspacing="0" cellpadding="0" style="width:100%;">
															<tr style="height: 25px">
																<td class="detail-content-label">
																	应收款编号
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" readonly v-model="model.SNo" placeholder="自动生成">
																</td>
																<td class="detail-content-info" colspan="2"></td>
															</tr>
															<tr style="height: 25px">
																<td class="detail-content-label">
																	客户
																</td>
																<td class="detail-content-info">
																	@{
																		if (Model.ID == 0)
																		{
																			<input type="text" class="detailedViewTextBox input-sm" v-model="model.PartnerName" readonly style="cursor:pointer;" onclick="openPopPartner();">
																			<button class="pure-button pure-button-edit pure-icon-bu" style="width: 23px; height: 21px;margin-right:5px;" title="选择" onclick="openPopPartner();return false;">
																				<i class="icon-search"></i>
																			</button>
																			<button class="pure-button pure-button-approve pure-icon-bu" style="width: 23px; height: 21px;" title="清除" onclick="clearPopPartner();return false;">
																				<i class="icon-remove"></i>
																			</button>
																		}
																		else
																		{
																			<input type="text" class="detailedViewTextBox input-sm" v-model="model.PartnerName" readonly style="font-weight:bold;border:none;box-shadow:none;" disabled />
																		}
																	}
																</td>
																<td class="detail-content-label">
																	销售订单
																</td>
																<td class="detail-content-info" style="font-weight:bold;color:#000;">
																	{{model.StockOutOrderSNo}}
																	@*<input type="text" class="detailedViewTextBox input-sm" v-model="model.StockOutOrderSNo" readonly style="cursor:pointer;" onclick="openStockOutOrder();" :disabled="model.SupplierName||model.BackSNo">
																		<button class="pure-button pure-button-edit pure-icon-bu" style="width: 23px; height: 21px;margin-right:5px;" title="选择" onclick="openStockOutOrder();return false;" :disabled="model.SupplierName||model.BackSNo">
																			<i class="icon-search"></i>
																		</button>
																		<button class="pure-button pure-button-approve pure-icon-bu" style="width: 23px; height: 21px;" title="清除" onclick="clearStockOutOrder();return false;" :disabled="model.SupplierName||model.BackSNo">
																			<i class="icon-remove"></i>
																		</button>*@
																</td>
																<td class="detail-content-label"></td>
																<td class="detail-content-info"></td>
															</tr>
															<tr style="height: 25px">
																<td class="detail-content-label">
																	供应商
																</td>
																<td class="detail-content-info">
																	@{
																		if (Model.ID == 0)
																		{
																			<input type="text" class="detailedViewTextBox input-sm" v-model="model.SupplierName" readonly style="cursor:pointer;" onclick="openSupplier();" :disabled="!!model.MemberName||!!model.StockOutOrderSNo">
																			<button class="pure-button pure-button-edit pure-icon-bu" style="width: 23px; height: 21px;margin-right:5px;" title="选择" onclick="openSupplier();return false;" :disabled="!!model.MemberName||!!model.StockOutOrderSNo">
																				<i class="icon-search"></i>
																			</button>
																			<button class="pure-button pure-button-approve pure-icon-bu" style="width: 23px; height: 21px;" title="清除" onclick="clearSupplier();return false;" :disabled="!!model.MemberName||!!model.StockOutOrderSNo">
																				<i class="icon-remove"></i>
																			</button>
																		}
																		else
																		{
																			<input type="text" class="detailedViewTextBox input-sm" v-model="model.SupplierName" readonly style="font-weight:bold;border:none;box-shadow:none;" disabled />
																		}
																	}
																</td>
																<td class="detail-content-label">
																	采购退货单
																</td>
																<td class="detail-content-info" style="font-weight:bold;color:#000;">
																	{{model.BackSNo}}
																	@*<input type="text" class="detailedViewTextBox input-sm" v-model="model.BackSNo" readonly style="cursor:pointer;" onclick="openBack();" :disabled="model.MemberName||model.StockOutOrderSNo">
																		<button class="pure-button pure-button-edit pure-icon-bu" style="width: 23px; height: 21px;margin-right:5px;" title="选择" onclick="openBack();return false;" :disabled="model.MemberName||model.StockOutOrderSNo">
																			<i class="icon-search"></i>
																		</button>
																		<button class="pure-button pure-button-approve pure-icon-bu" style="width: 23px; height: 21px;" title="清除" onclick="clearBack();return false;" :disabled="model.MemberName||model.StockOutOrderSNo">
																			<i class="icon-remove"></i>
																		</button>*@
																</td>
															</tr>
															<tr>
																<td class="detail-content-label" width="20%">
																	应收日期
																</td>
																<td class="detail-content-info" width="30%">
																	<input type="text" class="detailedViewTextBox input-sm calendar" name="DueDate" style="cursor:pointer;" maxlength="19" readonly />
																	<i class="icon-calendar calendar-tgr"></i>
																</td>
																<td class="detail-content-label label-required" width="20%">
																	应收金额
																</td>
																<td class="detail-content-info" width="30%">
																	<input type="number" class="detailedViewTextBox input-sm validate[required]" v-model="model.TotalRecvDue" style="font-weight:bold;">
																</td>
															</tr>
															<tr>
																<td class="detail-content-label">
																	应收款期次
																</td>
																<td class="detail-content-info">
																	<input type="text" class="detailedViewTextBox input-sm" v-model="model.Stage">
																</td>
																<td class="detail-content-label">
																	是否需要开发票
																</td>
																<td class="detail-content-info">
																	<input type="checkbox" v-model="model.Invoice" />开发票
																</td>
															</tr>
															<tr>
																<td class="detail-content-label">
																	备注
																</td>
																<td class="detail-content-info" colspan="3">
																	<textarea v-model="model.Comment" style="height:35px;"></textarea>
																</td>
															</tr>
														</table>
													</td>
												</tr>
												<tr style="height: 38px;">
													<td style="text-align:center;">
														<button type="submit" class="pure-button pure-button-edit" onclick="$('#frmEdit').submit();return false;" style="margin-right:50px;">
															<i class="icon-check"></i>&nbsp;保存&nbsp;
														</button>
														<button class="pure-button" @@click.prevent='pageBack'>
															<i class="icon-undo"></i>&nbsp;取消&nbsp;
														</button>
													</td>
												</tr>
											</tbody>
										</table>
									</div>
								</form>
							</td>
							<td class="detail-right-td" style="">
								<div class="detail-panel-div">
									<div class="detail-inner">
										<table border="0" cellpadding="5" cellspacing="0" class="module-tool-tab" style="width:100%;">
											<tr>
												<td align="left" class="genHeaderSmall" style="padding:5px;">操作</td>
											</tr>
											<tr>
												<td align="left" style="padding:5px;">
													<img src="~/theme/img/pointer.gif" hspace="5" />
													<a href="javascript:void(0);" class="webMnu" target="_blank">修改日志</a>
												</td>
											</tr>
										</table>
									</div>
								</div>
							</td>
						</tr>
					</table>
				</div>
			</td>
		</tr>
	</tbody>
</table>
@section footer {
	<script src="~/js/related/sys_attachment.js" asp-append-version="true"></script>
	<script src="~/js/pinyin.js" asp-append-version="true"></script>
	<script src="~/lib/jquery.autocomplete-1.4.10.js" asp-append-version="true"></script>
	@*日期必须开始*@
	<script src="~/lib/laydate/laydate.js" asp-append-version="true"></script>
	@*日期必须结束*@
	<script src="~/lib/validationEngine/jquery.validationEngine.min.js" asp-append-version="true"></script>
	<script src="~/lib/validationEngine/jquery.validationEngine-zh_CN.js" asp-append-version="true"></script>
	<link href="~/lib/validationEngine/validationEngine.jquery.css" rel="stylesheet" asp-append-version="true" />
	@*验证结束*@
	@*列表相关开始*@
	<script type="text/javascript">
		var pageEnumData = {
			state:@(Json.Serialize(ViewBag.StateOptions)),
		};
		var modelJson=@(Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model, new Newtonsoft.Json.JsonSerializerSettings()
		   {
			   DateFormatString = "yyyy-MM-dd HH:mm:ss"
		   })));
		var modelData = $.extend(modelJson, {
		});
		var pageData = {
			hideBreadcrumb: false,
			serviceCode: '@(ViewBag.ServiceCode)',
			global: globalData,
			viewid: 'main',
			related: @(Json.Serialize(ViewBag.RelatedModules)),
			model:modelData
		};

		var pageApp = new Vue({
			el: '#app',
			data: pageData,
			created: function () {
			},
			mounted: function () {
			},
			methods: {
				pageBack: function() {
					//history.go(-1);
					if (@(Model.ID > 0 ? "true" : "false")) {
						history.back();
					} else {
						location.href = '@(Url.Action("List", "FinanceRecvDue"))?nc=' + new Date().getTime();
					}
				},
				pageSave: function() {
					utils.ajaxPost('@(Url.Action("Save", "FinanceRecvDue"))', this.model, function (resp) {
						console.log(resp.data);
						utils.success("保存成功");
						location.href = '@(Url.Action("ViewDetail", "FinanceRecvDue", new { id = "" }))/'+resp.data+'?nc=' + new Date().getTime();
					}, function (msg) {
						utils.alert(msg);
					});
				},
				relatedChange: function (vid, e) {
					switch (e.action) {
						case "total":
							{
								this.related = this.related.map(function (item) {
									if (item.id == vid) {
										return Object.assign({}, item, { count: e.data });
									} else {
										return item;
									}
								});
							}
							break;
					}
				},
				changeView: function(vid) {
					this.viewid = vid;
					this.$refs[vid]&&this.$refs[vid].reload();
				},
				resetView: function() {
					this.viewid = 'main';
				}
			},
			computed: {
				currentM: function () {
					var currentM = null;
					var i;
					var j;
					for (i = 0; i < this.global.modules.length; i++) {
						for (j = 0; j < this.global.modules[i].Services.length; j++) {
							if (this.serviceCode == this.global.modules[i].Services[j].Code) {
								currentM = this.global.modules[i];
								break;
							}
						}
					}
					return currentM;
				},
				currentS: function () {
					var currentS = null;
					var i;
					var j;
					for (i = 0; i < this.global.modules.length; i++) {
						for (j = 0; j < this.global.modules[i].Services.length; j++) {
							if (this.serviceCode == this.global.modules[i].Services[j].Code) {
								currentS = this.global.modules[i].Services[j];
								break;
							}
						}
					}
					return currentS;
				}
			}
		});

		$(document).ready(function () {
			$("#frmEdit").keypress(function (e) {
				if (e.keyCode == 13) {
					return false;
				}
			}).validationEngine({
				scroll: false,
				validateNonVisibleFields: false,
				autoHidePrompt: true,
				showOneMessage: true,
				ajaxFormValidationMethod: 'post',
				onValidationComplete: function (form, status) {
					if (!status) {
						return;
					}
					if ((!pageApp.model.PartnerID || !pageApp.model.PartnerName)) {
						utils.alert("请选择客户");
						return;
					}
					pageApp.pageSave();
				}
			});

			$('.calendar-tgr').each(function (eidx, elem) {
				var $this = $(elem);
				var input = $this.prev('input')[0];
				$this.click(function () {
					laydate.render({
						elem: input
						, value: modelData[input.name] && modelData[input.name].substr(0, 10) || ''
						, show: true //直接显示
						, closeStop: $this[0]
						, done: function (value, date) {
							pageApp.model = Object.assign({}, pageApp.model, _defineProperty({}, input.name, value));
						}
					});
				});
			});

			$('.calendar').each(function (eidx, elem) {
				var $this = $(elem);
				var input = $this[0];
				laydate.render({
					elem: input
					, value: modelData[input.name] && modelData[input.name].substr(0, 10) || ''
					, closeStop: $this.next('i')[0]
					, done: function (value, date) {
						pageApp.model = Object.assign({}, pageApp.model, _defineProperty({}, input.name, value));
					}
				});
			});
		});

		function openPopPartner() {
			utils.layerFull('@(Url.Action("PopList", "IMS_Partner"))?type=@((int)PartnerType.布行)&callback=popPartnerCallback', '选择往来单位', 'Partner');
		}

		function popPartnerCallback(index, ret) {
			if (!ret) {
				return;
			}
			modelData.PartnerID = ret.ID;
			modelData.PartnerName = ret.Name;//
		}

		function clearPopPartner() {
			modelData.PartnerID = 0;
			modelData.PartnerName = "";
			modelData.StockOutOrderSNo = "";
			modelData.StockOutOrderID = 0;
			modelData.BackSNo = "";
			modelData.BackID = 0;
		}
	</script>
	@*列表相关结束*@
}